<?php
//
// +------------------------------------------------------------------------+
// | PHP Version 5.4                                                        |
// +------------------------------------------------------------------------+
// | Copyright (c) All rights reserved.                                     |
// +------------------------------------------------------------------------+
// | 世纪车来车往(北京）网络科技有限公司 版权所有！                               |
// | TEL:010-63732365  HOTLINE:400-6688-365  EMAIL:clcw@clcw.com.cn         |
// | $Revision: 1.0 $                                                       |
// +------------------------------------------------------------------------+
// | Author: xiangminghu@clcw.com.cn                                        |
// +------------------------------------------------------------------------+
//

namespace AuctionBack\Logic;


class ActivitySupermanLogic extends BaseLogic
{
    protected $autoCheckFields = false;

    protected $activitySupermanModel;

    public function _initialize()
    {
        $this->activitySupermanModel = D('ActivitySuperman', 'Model');
    }

    /**
     * 已发放
     *
     * @param       $page
     * @param       $pageSize
     * @param array $params
     *
     * @return array
     */
    public function getSendList($page, $pageSize, $params = [])
    {
        $page = $page < 1 ? 1 : (int)$page;
        $pageSize = $pageSize < 1 ? 10 : (int)$pageSize;
        $map = [];
        $map['act_code'] = ['neq', ''];
        if ($params['code']) {
            $map['act_code'] = ['eq', $params['code']];
        }
        if ($params['user_id']) {
            $map['user_id'] = ['eq', $params['user_id']];
        }
        if ($params['mobile']) {
            $map['mobile'] = ['eq', $params['mobile']];
        }
        if ($params['start']) {
            $map['update_time'] = ['egt', strtotime($params['start'])];
        }
        if ($params['end']) {
            $map['update_time'] = ['elt', strtotime($params['end'])];
        }
        if ($params['start'] && $params['end']) {
            $map['update_time'] = [
                ['egt', strtotime($params['start'])],
                ['elt', strtotime($params['end'])]
            ];
        }
        $total = $this->activitySupermanModel->where($map)->count();
        $list = $this->activitySupermanModel
            ->where($map)
            ->page($page, $pageSize)
            ->select();

        return [
            'total' => $total,
            'list'  => $list
        ];
    }

    /**
     * 已达标待发卡券
     *
     * @param       $page
     * @param       $pageSize
     * @param array $params
     *
     * @return array
     */
    public function getStandardList($page, $pageSize, $params = [])
    {
        $page = $page < 1 ? 1 : (int)$page;
        $pageSize = $pageSize < 1 ? 10 : (int)$pageSize;
        $map = [];
        $map['act_code'] = ['eq', ''];
        $map['finish_time'] = ['gt', 0];
        if ($params['user_id']) {
            $map['user_id'] = ['eq', $params['user_id']];
        }
        if ($params['mobile']) {
            $map['mobile'] = ['eq', $params['mobile']];
        }
        $total = $this->activitySupermanModel->where($map)->count();
        $list = $this->activitySupermanModel->where($map)
            ->page($page, $pageSize)
            ->select();

        return [
            'total' => $total,
            'list'  => $list
        ];
    }
}